clearvars -except Globaloption option

%% Saving parameter estimates to automatically update the paper
fID = fopen(['../../results/tables_main/UK/pre1946/TableEst_pre_UK_cy_partial.tex'], 'w');

%% Baseline Results
loaddata_4CIjoint_annual_cy_partial;

fprintf(fID, '\\newcommand{\\cymeanUKprelong}{%4.0f}\n', round(mean([cy_long1; cy_long2] * 100)));
fprintf(fID, '\\newcommand{\\cymeanUKprelongpct}{%4.2f}\n', mean([cy_long1; cy_long2]));
fprintf(fID, '\\newcommand{\\cymeanUKpreshort}{%4.0f}\n', round(mean([cy_short1; cy_short2] * 100)));

fprintf(fID, '\\newcommand{\\cymeanUKprelongone}{%4.0f}\n', round(mean([cy_long1] * 100)));
fprintf(fID, '\\newcommand{\\cymeanUKprelongtwo}{%4.0f}\n', round(mean([cy_long2] * 100)));
fprintf(fID, '\\newcommand{\\cygdpmeanUKprelongone}{%4.2f}\n', mean([cy_data1] * 100));
fprintf(fID, '\\newcommand{\\cygdpmeanUKprelongtwo}{%4.2f}\n', mean([cy_data2] * 100));
fprintf(fID, '\\newcommand{\\cygdpmeanUKpre}{%4.2f}\n', mean(seig_rev(2:end)) * 100);

option.robust = 4;
filename = ['MAT/cy_UK_case', num2str(option.robust)];
load (filename);
fprintf(fID, '\\newcommand{\\upperUKpre}{%4.2f}\n', upper);
fprintf(fID, '\\newcommand{\\upperUKprepct}{%4.2f}\n', 100 * upper);
fprintf(fID, '\\newcommand{\\smeanUKpre}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\smeanUKprepct}{%4.2f}\n', 100 * mean(s));
fprintf(fID, '\\newcommand{\\preukcorrpvscydebtactualcy}{%4.2f}\n', corr(gdebt(2:end), s'));
fprintf(fID, '\\newcommand{\\preukpvscytodebtactualcy}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));
fprintf(fID, '\\newcommand{\\preukuppertodebtactualcy}{%4.2f}\n', 100 * upper / nanmean(gdebt));
fprintf(fID, '\\newcommand{\\cypreukpdgdp}{%4.2f}\n', mean(exp(pxbar)));

option.robust = 6;
filename = ['MAT/cy_UK_case', num2str(option.robust)];
load (filename);
fprintf(fID, '\\newcommand{\\upperUKpreconst}{%4.2f}\n', upper);
fprintf(fID, '\\newcommand{\\upperUKpreconstpct}{%4.2f}\n', upper * 100);
fprintf(fID, '\\newcommand{\\smeanUKpreconst}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\smeanUKpreconstpct}{%4.2f}\n', mean(s) * 100);
fprintf(fID, '\\newcommand{\\preukpvsconstcytodebt}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));
fprintf(fID, '\\newcommand{\\preukcorrpvsconstcydebt}{%4.2f}\n', corr(gdebt(2:end), s'));
fprintf(fID, '\\newcommand{\\preukupperconstcytodebt}{%4.2f}\n', 100 * upper / nanmean(gdebt));

option.robust = 7; % constant cy/bdp with 2 % output_rp
filename = ['MAT/cy_UK_case', num2str(option.robust)];
load (filename);
fprintf(fID, '\\newcommand{\\upperUKpreconsttwenty}{%4.2f}\n', upper);
fprintf(fID, '\\newcommand{\\upperUKpreconsttwentypct}{%4.2f}\n', upper * 100);
fprintf(fID, '\\newcommand{\\smeanUKpreconsttwenty}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\smeanUKpreconsttwentypct}{%4.2f}\n', mean(s) * 100);
fprintf(fID, '\\newcommand{\\preukcorrpvscyconstdebttwenty}{%4.2f}\n', corr(gdebt(2:end), s'));
fprintf(fID, '\\newcommand{\\preukpvscyconsttodebttwenty}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));

option.robust = 5; % varying cy/bdp with 2 % output_rp
filename = ['MAT/cy_UK_case', num2str(option.robust)];
load (filename);
fprintf(fID, '\\newcommand{\\uppercyUKpretwenty}{%4.2f}\n', upper);
fprintf(fID, '\\newcommand{\\uppercyUKpretwentypct}{%4.2f}\n', upper * 100);
fprintf(fID, '\\newcommand{\\smeancyUKpretwenty}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\smeancyUKpretwentypct}{%4.2f}\n', mean(s) * 100);
fprintf(fID, '\\newcommand{\\preukcorrpvscydebttwenty}{%4.2f}\n', corr(gdebt(2:end), s'));
fprintf(fID, '\\newcommand{\\preukpvscytodebttwenty}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));
fprintf(fID, '\\newcommand{\\preukuppertodebttwenty}{%4.2f}\n', 100 * upper / nanmean(gdebt));

load MAT/UKprepara_20.mat; %upper bound without cy
fprintf(fID, '\\newcommand{\\upperUKpretwenty}{%4.2f}\n', upper);
fprintf(fID, '\\newcommand{\\upperUKpretwentypct}{%4.2f}\n', upper * 100);
fprintf(fID, '\\newcommand{\\smeanUKpretwenty}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\smeanUKpretwentypct}{%4.2f}\n', mean(s) * 100);
fprintf(fID, '\\newcommand{\\preukcorrpvsdebttwenty}{%4.2f}\n', corr(gdebt(2:end), s'));
fprintf(fID, '\\newcommand{\\preukpvstodebttwenty}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));

load MAT/debtinVAR_cy_partial_UK_pre1945.mat
fprintf(fID, '\\newcommand{\\upperUKprecydebtVAR}{%4.2f}\n', upper);
fprintf(fID, '\\newcommand{\\upperUKprecydebtVARpct}{%4.2f}\n', upper * 100);
fprintf(fID, '\\newcommand{\\smeanUKprecydebtVAR}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\smeanUKprecydebtVARpct}{%4.2f}\n', mean(s) * 100);
fprintf(fID, '\\newcommand{\\preukcorrpvscydebtcydebtVAR}{%4.2f}\n', corr(gdebt(2:end), s'));
fprintf(fID, '\\newcommand{\\preukpvscytodebtcydebtVAR}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));
fprintf(fID, '\\newcommand{\\preukuppertodebtcydebtVAR}{%4.2f}\n', 100 * upper / nanmean(gdebt));

load MAT/debtinVAR_UK_pre1945.mat
fprintf(fID, '\\newcommand{\\upperUKpredebtVAR}{%4.2f}\n', upper);
fprintf(fID, '\\newcommand{\\upperUKpredebtVARpct}{%4.2f}\n', upper * 100);
fprintf(fID, '\\newcommand{\\smeanUKpredebtVAR}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\smeanUKpredebtVARpct}{%4.2f}\n', mean(s) * 100);
fprintf(fID, '\\newcommand{\\preukcorrpvscydebtdebtVAR}{%4.2f}\n', corr(gdebt(2:end), s'));
fprintf(fID, '\\newcommand{\\preukpvscytodebtdebtVAR}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));

option.robust = 8; % 1.5 % output_rp
filename = ['MAT/cy_UK_case', num2str(option.robust)];
load (filename);
fprintf(fID, '\\newcommand{\\pdgdpUKpreonepointfive}{%4.2f}\n', mean(exp(pxbar)));
fprintf(fID, '\\newcommand{\\upperUKpreonepointfivepct}{%4.2f}\n', upper * 100);
fprintf(fID, '\\newcommand{\\smeanUKpreonepointfivepct}{%4.2f}\n', mean(s) * 100);

option.robust = 9; % cy * 4
filename = ['MAT/cy_UK_case', num2str(option.robust)];
load (filename);
fprintf(fID, '\\newcommand{\\upperUKprethreecypct}{%4.2f}\n', upper * 100);
fprintf(fID, '\\newcommand{\\smeanUKprethreecypct}{%4.2f}\n', mean(s) * 100);
fprintf(fID, '\\newcommand{\\seigUKprethreecypct}{%4.2f}\n', mean(seig_rev) * 100);

%% Close File
fclose(fID);
